package com.example.demo.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TimeAdvice {

    @Pointcut("execution(* com.example.demo.service..*.find*(..))")
    public void pt(){

    }

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp){

        Object result = null;

        try {
            long startTime = System.currentTimeMillis();
            result= pjp.proceed();
            long endTime = System.currentTimeMillis();
            String name = pjp.getSignature().getName();
            System.out.println(name + "运行耗时:" + (endTime - startTime));

        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
         return result;
    }


}
